<?php
/**
 * Enter description here...
 *
 * @author littlexiang
 * @version $Id: Form.php 685 2009-08-03 06:28:25Z songxiang $
 */

class Form extends Form_Abstract implements Form_Interface 
{
    private $_elementStack;
    
    public function getValue ()
    {
        foreach ($this->_elementStack as $element) {
            if (! $element['ignore']) {
                $element = $element['element'];
                $element->setValue($this->_rawData[$element->name]);
                $this->_cleanData[$element->name] = $element->getValue();
            }
        }
        return $this->_cleanData;
    }
    
    public function setValue ($value)
    {
        $this->_rawData = $value;
    }
    
    /**
     * 
     * @param object $formElement
     * @param bool $ignore optional
     */
    public function addElement ($formElement, $ignore = false)
    {
        $this->_elementStack[] = array('element' => $formElement , 'ignore' => $ignore);
    }
    
    /**
     * @return string the form html
     */
    public function render ()
    {
        $html = "<form ";
        foreach ($this->_attributes as $key => $attribute) {
            $html .= $key . "=\"$attribute\" ";
        }
        $html.='>';
        
        foreach ($this->_elementStack as $element) {
            $html .= $element['element'];
        }
        $html .= "</form>";
        return $html;
    }
    
    public function isValid ()
    {
        return true;
    }

}
?>